<?php
/**
 * 我的消息模块
 * User: zhc
 * Date: 2018/11/1 0001
 * Time: 21:35
 */

namespace app\wx\controller;
use  library\Validator;
use module\MessageApi;
class Message extends  CommonController
{

     /**
      *  我的消息列表
      */
    public  function  getMessList(){

//        list($type) = Validator::make($this->request->request(), [
//            'type' => 'required', //1 系统消息  2通知消息
//        ]);

       $list=MessageApi::getMessagelist($this->uid,1);
       return $this->fetch('mess/list',['list'=>$list]);
    }
    /**
     *  消息详情
     */
    public  function  getMessInfo(){

        list($mn_id) = Validator::make($this->request->request(), [
            'mn_id' => 'required',
        ]);
        $list=MessageApi::getMessageInfo($mn_id);
        return $this->response->api($list);
    }
    /**
     * 更新消息已读状态
     */
    public function upMessageStatus(){
        list($ids) = Validator::make($this->request->request(),[
            'ids' => 'regex:/^\d+(\,\d+)*$/',
        ]);
        $re=MessageApi::readMessage($this->uid,$ids);
        return $this->response->api([],self::SUCCESS_CODE,'更新成功');
    }
    /**
     *  删除消息
     */
    public  function  deleteMess(){

        list($mn_id) = Validator::make($this->request->request(), [
            'mn_id' => 'required',
        ]);
        $re=MessageApi::deleteMess(['mn_id'=>$mn_id,'ui_id'=>$this->uid]);
        if($re !==false){
            return $this->response->api([]);
        }else{
            return $this->response->api([],self::ERROR_CODE);
        }
    }
}